<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('通知中心')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
		.layui-tab{margin:0px}
		.layui-tab-content{padding: 0 15px;border: 1px solid #0087fa;margin: 0px;border-bottom: 0;background: #FFFFFF}
		.layui-textarea{margin-bottom: 5px;}
		.layui-input{line-height: 30px;}
		.layui-input,.layui-textarea{text-align: left;}
		.layui-table-tool-self {top: 3px;}
	</style>
</head>
<body>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
			<div class="panel-header">
				<div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
					<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
						<i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
					</a>
				</div>
			</div>
			<div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
		<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
	</div>
	<div class="mid-content">
		<div class="layui-tab" lay-filter="dhtab">
			<ul class="layui-tab-title">
				<li listUrl="/system/modulenotice/listwd" class="layui-this">未读</li>
				<li listUrl="/system/modulenotice/listyd">已读</li>
				<li listUrl="/system/modulenotice/listfs">已发送</li>
			</ul>
			<div class="layui-tab-content">
				<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
			</div>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<!-- 特殊字段自定义模板 -->
<script type="text/html" id="templet_taskState">
	{{# if(d.taskState=='未读'){return "<span style='color:blue'>未读</span>"; }}
	{{# }else if(d.taskState.indexOf('超时')>-1){return "<span style='color:red'>"+d.taskState+"</span>"; }}
	{{# }else{return "<span style='color:green'>"+d.taskState+"</span>";} }}
</script>
<!-- 操作区 -->
<script type="text/html" id="toolbar">
	<div class="layui-btn layui-table-tools" lay-event="batchRead" style="margin-top: 5px;">
		<p class="dhicon dh-pencil-square-o	" style="color:white;font-size:14px"><span class="fa_span" style="color:white">批量已读</span></p>
	</div>
</script>
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-eye" onclick="read('{{d.LAY_TABLE_INDEX}}')">&nbsp;查看</a>
	{{# if(d.pageURL && d.pageURL!='#'){ }}
	<a class="layui-btn layui-btn-xs dhicon dh-search layui-btn-warm" onclick="newTab('{{d.pageURL}}','{{d.pageTitle}}','{{d.cUser}}','{{d.cUserName}}','{{d.moduleTable}}','{{d.pageTitle}}');">&nbsp;详情</a>
	{{# } }}
</script>
<!-- 查看详情 -->
<script id="detail" type="text/template">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="width:calc(100%-30px)">
		<div class="layui-form-item margin_t0">
			<div class="'layui-inline margin_r0" th:each="field : ${gridColumns.dictionaryForPageFieldList}" th:if="${field.fieldFrontTop eq 1}">
				<label class="layui-form-label">[[${field.fieldName}]]：</label>
				<div class="layui-input-block">
					<div th:if="${field?.fields eq 'taskAbstract'}" name="taskAbstract" id="taskAbstract" class="layui-textarea canntEdit"></div>
					<div th:if="${field?.fields ne 'taskAbstract'}" th:name="${field?.fields}" th:id="${field?.fields}" class="layui-input canntEdit"></div>
				</div>
			</div>
		</div>
	</div>
</script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + [[${prefix}]],
			gridColumns=[[${gridColumns}]],
			moduleTable=[[${moduleTable}]],
			session=[[${session}]];
	/*]]>*/
</script>
<script type="text/javascript">
	var $,layer,form,element,table,laydate,wherestr={};
	layui.use(['table','form','layer','jquery','element','laydate'], function () {
		$ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, element = layui.element,laydate =layui.laydate;
		serachRender();//查询条件初始渲染集合
		refreshNotice();//刷新通知数量
		$.tablelist.init({//默认加载未读通知
			elem: '#dhtable'
			,url: prefix + '/listwd'
			,even:true
			,totalRow: gridColumns.totalRow
			,toolbar: '#toolbar'
			,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
			,cols:[gridColumns.gridBody
			]
			,height:'full-75'
			,where: {field: 'createTime',order: 'desc'}
		});
		//监听Tab页
		element.on('tab(dhtab)', function(data){
			$.tablelist.init({//dhtable初始化,替换数据源
				elem: '#dhtable',
				url:$(this).attr('listUrl'),
				even:true,
				toolbar:data.index?'':'#toolbar',
				height:'full-75',
				totalRow: gridColumns.totalRow,
				toolbar: data.index==0?'#toolbar':true,
				defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}],
				cols:[gridColumns.gridBody
				],
				where: {field: 'createTime',order: 'desc'}
			});
		});
		//头工具栏事件
		table.on('toolbar(ftable)', function(obj){
			switch(obj.event){
				case 'fieldSet'://列设置
					filedSet(moduleTable);
					break;
				case 'batchRead'://批量已读
					if(table.checkStatus('dhtable').data.length>0){
						$.operate.remove("是否将这"+table.checkStatus('dhtable').data.length+"条通知设置为已读？",prefix + "/toreadpost/",{'infoItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
							table.reload('dhtable');
							refreshNotice();//刷新通知数量
						});
					}else{
						layer.msg("无勾选数据！",{icon:7});
					};
					break;
			};
		});
		//监听排序事件
		table.on('sort(ftable)', function(obj){
			$.tablelist.sort('dhtable',obj);
		});
	});
	$(".layui-tab-content").css("border-color",JSON.parse(window.localStorage.getItem('layuiAdmin')).theme.color.header)
	function newTab(url,title,cid,cname,mt,tc){//打开详情页
		if(mt=="THR_TrainingAppraiseLecturer"){//特殊页面只需用弹出窗查看
			$.modal.openSimple(title+'-'+cname+'('+cid+')',url,($(window).width() - 300),($(window).height() - 150));
		}else{//打开对应的单据页面
			if(top.layui.index)top.layui.index.openTabsPage(url,tc);
			else window.open(url);
		}
	}
	function read(tIndex){//查看
		var chooseData=table.cache.dhtable[tIndex];//选中行的数据
		if($('[lay-filter=dhtab] .layui-this').index()==0){//选中未读选项卡
			layer.open({
				type: 1,
				area: [($(window).width() - 400)+'px', ($(window).height() - 200)+'px'],
				fix: false,//不固定
				offset: '10%',//距离顶部
				maxmin: true,//最大最小化
				shade: 0.3,//遮罩
				title: '查看详情',
				content: $('#detail').html(),
				btn: ['已读', '关闭'],
				shadeClose: true,// 弹层外区域关闭
				success: function(layero, index){
					$.each(chooseData,function(i,v){
						$('#'+i).html(v);
					})
				},
				yes: function(index, layero){
					var postData=[];
					postData.push(chooseData);
					$.operate.post(prefix+'/toreadpost', {'infoItems':JSON.stringify(postData, null, 2)}, function(res){
						if(res.code == 0){
							layer.close(index);
							table.reload('dhtable');
							refreshNotice();//刷新通知数量
						}
					});
				}
			});
		}else{
			layer.open({
				type: 1,
				area: [($(window).width() - 400)+'px', ($(window).height() - 200)+'px'],
				fix: false,//不固定
				offset: '10%',//距离顶部
				maxmin: true,//最大最小化
				shade: 0.3,//遮罩
				title: '查看详情',
				content: $('#detail').html(),
				btn: ['关闭'],
				shadeClose: true,// 弹层外区域关闭
				success: function(layero, index){
					$.each(chooseData,function(i,v){
						$('#'+i).html(v);
					})
				}
			});
		}
	}
	function refreshNotice(){//刷新通知数量
		$.get(prefix + '/listwds',function(res){//查询未读通知数
			if(res.data[0].noticeCount>0){
				parent.$('#notice').text(res.data[0].noticeCount);
				parent.$('#notice').show();
			}else{
				parent.$('#notice').hide();
			};
		});
	}
</script>
</body>
</html>